<?php

class Node {
    
    /**
     * token type
     * @var int
     */
    public $type;
    
    /**
     * 父亲节点
     * @var Node
     */
    public $parentNode;
    
    /**
     * 下一个兄弟节点
     * @var Node
     */
    public $nextNode;
    
    /**
     * 第一个儿子节点
     * @var Node
     */
    public $firstChild;
    
    /**
     * 最后一个儿子节点
     * @var Node
     */
    public $lastChild;
    
    /**
     * line number
     * @var int
     */
    public $lineNumber = -1;
    
    /**
     * @var int
     */
    public $position = -1;
    
    public function __construct() {
        $this->firstChild = NULL;
        $this->lastChild = NULL;
        $this->nextNode = NULL;
        $this->parentNode = NULL;
    }
    
    public function addChildToBack(Node $child){
        $child->nextNode = NULL;
        
        if($this->lastChild == NULL){
            $this->firstChild = $this->lastChild = $child;
        }
        else{
            $this->lastChild->nextNode = $child;
            $this->lastChild = $child;
        }
    }
    
    public function setParent(Node $parent) {
        if ($this->parentNode == $parent) {
            return;
        }
        $this->parentNode = $parent;
    }
    
}